/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author PhucAnh
 */
public class Curve extends Shape{
    Point[] p;
    int n;
    Color cl;
    int str;

    
    public Curve() {
        n=0; 
        str = 5;
    }
    
    public Curve(Color color, int basicStrok){
        super(color, basicStrok);
        
        cl = color;
        str = basicStrok;
        n=0; 
    }

    public Color getCl() {
        return cl;
    }

    public void setCl(Color cl) {
        this.cl = cl;
    }

    public int getStr() {
        return str;
    }

    public void setStr(int str) {
        this.str = str;
    }
    public void addPoint(Point d)
    {
        
        if(n==0)
        {
            p=new Point[1];
            p[n]=d;
            n++;
        }
        else
        {
        Point[] temp = new Point[n+1];
        for(int i=0;i<n;i++) {
                temp[i] = p[i];
            }
        temp[n]= d;
        p= new Point[n+1];
        p = temp;
        n++;
        }

    }

    public void setP(Point[] p) {
        this.p = p;
    }

    public void setN(int n) {
        this.n = n;
    }

    public Point[] getP() {
        return p;
    }

    public int getN() {
        return n;
    }
    @Override
    public void toMove(int m,int n)
    {
        for(int i= 0;i<this.getN();i++)
        {
            p[i].toMove(m, n);
        }
    }
    
    @Override
    public void drawShape(Graphics g2,BufferedImage img)
    {
        Graphics2D g= (Graphics2D)g2;
        g.setStroke(new BasicStroke(str));
            g.setColor(cl);
            if(this.getN()>1)
            {          
                for(int i = 0;i<this.getN()-1;i++)
                {
                    g.drawLine(this.getP()[i].getX(), this.getP()[i].getY(),this.getP()[i+1].getX(),this.getP()[i+1].getY());
                }          
            }       
    }   
 
    public void replay(Graphics g,int time,Image a,Control.PlayBack.MyPanel1 a2){
        Graphics2D g2D= (Graphics2D)g;
        g2D.setStroke(new BasicStroke(str));
        g.setColor(cl);
        Image img = a;
        Point tmp=new Point();

          if(this.getN()>1) {          
                for(int i = 0;i<this.getN()-1;i++) {
                    g.drawLine(this.getP()[i].getX(), this.getP()[i].getY(),this.getP()[i+1].getX(),this.getP()[i+1].getY());
                    try {
                        Thread.sleep(time/5);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Curve.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }          
                     
        }
    }
}
